<? 
	$title="User List"; 
	$pageid="4";
	$accessid=",a10,";

	
	
	require("required/dbconnect.php"); 
	require("required/function.php");
	require("required/header.php");
	
	checkAccess("allow_gift_management",1);
?>

<script src="required/js/jquery-1.4.2.js"></script>
<script src="required/js/common_javascript.js"></script>
<?

		
	if(!empty($_GET['action']))
	{
		switch($_GET['action'])
		{
			case 1:
				$msg="<div class='dw_success'>Data Updated</div>";
				break;
			case 2:
				$msg="<div class='dw_failed'>Voucher code already exist,update failed!</div>";
				break;
			case 3:
				$msg="<div class='dw_success'>Data Updated</div>";
				break;	
			default:
				$msg="";
				break;
		}
		echo "<script>displayMsg('divMsg')</script>";	
	}else{
		$msg="";
	}
	
	

	

	
	
	
		
?>
<table width="100%"  cellpadding="0" cellspacing="5" height="300">
<tr>
	
	<script>
		function frmValidate(frm1)
		{
			if(document.frm1.voucher_name.value=="")
			{
				alert("please enter voucher name");
				return false;
			}
			
			if(document.frm1.voucher_code.value=="")
			{
				alert("please enter voucher code");
				return false;
			}
			
			return true;
		}
		
		function checkExist(field,divName,showName) {
			var value = document.getElementById(field).value;
			if(value!=""){
				
				changeContent('required/js/checkVoucherExist.php?field='+field+'&value='+value+'&showName='+showName,divName)
			}
		}
	</script>
	<td valign="top">
			
            
			<form action="bv_add2.php" method="post" name="frm1" onsubmit="return frmValidate(this)">
            <script language="JavaScript" type="text/javascript" src="required/js/goAjax.js"></script>
            <script type="text/javascript" src="required/js/calendarDateInput.js"></script>
			<table width="100%">
			
				<tr>
					<td colspan="3" class="title">
					<strong>Add Birthday Voucher</strong>					
					</td>
				</tr>
               <Tr>
               		<td colspan="3">
                   
                    <div id="divMsg"><?= $msg ?></div>
                    </td>
               </Tr>
               <tr>
                        	<td colspan="2" class="sub_title_line" ><br />Setting</td>
                        </tr>
                <tr>
					<td>Status</td><td width="82%">
  					<select name="status">
                    	<option value="1">Active</option>
                        <option value="0">Disabled</option>
                    </select>
  
  					</td>
			  	</tr>
                
                <tr>
               		<Td>Start Date</Td><td><script>
									DateInput('start_date', true, 'YYYY-MM-DD')</script></td>
               </tr>
               
               <tr>
               		<Td>End Date</Td><td><script>DateInput('end_date', true, 'YYYY-MM-DD')</script></td>
               </tr>		 
                <Tr>
               	  <td>Voucher Name</td><td width="82%"><input type="text" value="" name="voucher_name" maxlength="50" size="30"></td>
             	</Tr>
                <Tr valign="top">
               	  <td>Voucher Code</td><td width="82%">
                  <input type="text" value="" name="voucher_code" id="voucher_code" maxlength="50" size="30" onBlur="checkExist('voucher_code','divVoucherCode','Voucher code'); return false;">
                  <div id="divVoucherCode"></div>
                  
                  </td>
             	</Tr>
                <Tr>
               	  <td>Times To Use</td><td width="82%"><input type="text" value="" name="times_to_use" id="times_to_use" maxlength="2" size="5" onkeyup="removeAlphabet(this.name)"></td>
             	</Tr>
                <tr>
					<td>Discount Amount</td><td width="82%"><input type="text" value="" name="discount_amount"  id="discount_amount" maxlength="3" size="5" onkeyup="removeAlphabet(this.name)">
  					<select name="discount_type">
                    	<option value="M">% Off</option>
                        <option value="P">$ Off</option>
                    </select>
  
  					</td>
			  </tr>
              <tr>
              	<Td>Minimum Order</Td><Td>RM <input type="text" value="" name="minimum_purchase"  id="minimum_purchase" maxlength="3" size="5" onkeyup="removeAlphabet(this.name)"></Td>
              </tr>
               <tr>
                 	<Td>Deliver email</Td><td><input type="text" name="send_from_day" id="send_from_day" value="7" maxlength="2"  size="5" onkeyup="removeAlphabet(this.name)"/> day(s) before birth date</td>
                 </tr>
                 <tr>
                 	<Td>Voucher Expiry at</Td><td><input type="text" name="expiry_day" id="expiry_day" value="0"  maxlength="2"  size="5" onkeyup="removeAlphabet(this.name)"/> 
                    day(s) after birth date (leave field blank  or &quot;0&quot; if there is no expiry)</td>
                 </tr>
                  <tr>
                 	<Td>For Birthday In Year</Td><td><input type="text" name="birthday_year" id="birthday_year" value="<?= date("Y") ?>"  maxlength="4"  size="5" onkeyup="removeAlphabet(this.name)"/> 
                   </td>
                 </tr>
              <tr>
                        	<td colspan="2" class="sub_title_line" ><br />Email Content</td>
                        </tr>
				 <tr valign="top">
                 	<Td>Use the keyword to replace the data in email's subject and content</Td>
                    <td> 
                    <table class="solidborder" width="400">
                        <tr class="table_header">
                            <td>Keyword</td><td>To replace </td>
                        </tr>
                        <tr>
                            <td>[%name%]</td><td>Member's name</td>
                        </tr>
                        <tr>
                           <td>[%voucher_code%]</td><td>Voucher code</td>
                        </tr>
                        <tr>
                           <td>[%birth_date%]</td><td>Member Birth Date</td>
                        </tr>
                         <tr>
                           <td>[%expiry_date%]</td><td>Voucher Expiry Date</td>
                        </tr>
                         <tr>
                           <td>[%minimum_purchase%]</td><td>Minimum Purchase</td>
                        </tr>
                        
                     </table>
                     
                     </td>
                 </tr>       
                
                 <tr>
                   <Td>Email Subject</Td><td><input type="text" value="" name="email_subject" size="50"   /></td>
                 </tr>
                 <tr valign="top">
                    <td>Email Content</td>  
                    <td width="82%" valign="top">
                                <? include_once("fckeditor/fckeditor.php") ?>
                                <?php
                                    $oFCKeditor = new FCKeditor('email_content') ;
                                    $oFCKeditor->ToolbarSet = 'DeswinBasic';
                                    $oFCKeditor->BasePath = './fckeditor/' ;
                                    $oFCKeditor->Value = "" ;
                                    $oFCKeditor->Create() ;
                                ?>             </td>
              </tr>
                
				
				
			
				<td width="18%">
                
				  <input type="submit" value="Save" class="button" name="btnsubmit">
                  <input type="button" value="Back" class="button" name="btnsubmit" onclick="window.open('bv_management.php','_self')">
				</td>
			</table>
			</form>
		</td>
	</tr>
	
	
</table>
<? require("required/footer.php"); ?>

